QuickOPC User's Guide and Reference
OPC-A&E Observables
Development Models > Reactive Programming Model > Reactive Programming Model for OPC Alarms and Events > OPC-A&E Observables

The AENotificationObservable class is an observable for notifications about OPC events. It represents a data stream with information about subscribed events.

Each significant change is represented by an OnNext message of type EasyAENotificationEventArgs. This message is used both for successes, when the Exception property is a null reference, and for failures, when the Exception property is non-null and contains the failure information.

The OnCompleted and OnError messages (methods of the IObserver) are never sent (not even in case of error related to the OPC server communication), thus the data stream is not terminated. If your application requires, you can process the data stream further, and filter it or split it by success/failure as needed.

You can create instances of AENotificationObservable either by using its constructor, or with use of several overloads of the static Create method. The static AENotificationObservable.Create methods use the default underlying EasyAEClient object for OPC reactive extensions. If you need to set some parameters in the client object, you can use the ClientSelector property to specify them. This allows the code be expressed only in terms of pure OPC logic, and be not tied to the actual way it is implemented.

It is recommended that you create the instances using the AENotificationObservable.Create methods unless you have special needs.

Example

// Shows how to create an observable for OPC-A&E notifications, and subscribe to it.

using System;
using System.Threading;
using OpcLabs.EasyOpc.AlarmsAndEvents.Reactive;

namespace ReactiveDocExamples
{
    namespace _AENotificationObservable
    {
        class Subscribe
        {
            public static void Main1()
            {
                Console.WriteLine("Creating observable...");
                AENotificationObservable events =
                    AENotificationObservable.Create("", "OPCLabs.KitEventServer.2", 1000);

                Console.WriteLine("Subscribing...");
                using (events.Subscribe(e => Console.WriteLine(
                    (e.Exception is null) ? (e.EventData?.Message ?? "") : e.Exception.GetBaseException().ToString())))
                {
                    Console.WriteLine("Waiting for 10 seconds...");
                    Thread.Sleep(10*1000);

                    Console.WriteLine("Unsubscribing...");
                }

                Console.WriteLine("Waiting for 2 seconds...");
                Thread.Sleep(2 * 1000);
            }
        }
    }
}
See Also

Examples - Reactive Programming